package Controle;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JComboBox;
import javax.swing.JOptionPane;

import DAO.XeroxDao;
import POJO.Xerox;

public class ctrlXerox 
{

	public JComboBox<String> BuscaXerox(JComboBox<String> cmbXerox)
	{
		if(cmbXerox.getItemCount() != 0)
		{
			cmbXerox.removeAllItems();
		}
		List<Xerox> listaXerox = new ArrayList<Xerox>();
		XeroxDao xDao = new XeroxDao();
		try 
		{
			listaXerox = xDao.listaXerox();
			for(Xerox x:listaXerox)
			{
				StringBuffer sXerox = new StringBuffer();
				sXerox.append(String.valueOf(x.getRg()));
				sXerox.append(" - ");
				sXerox.append(x.getDia());
				sXerox.append(" - ");
				sXerox.append(x.getHora());
				cmbXerox.addItem(sXerox.toString());				
			}
		} catch (SQLException e) 
		{
			JOptionPane.showMessageDialog(null, e.getMessage(), "Erro na listagem de xerox", JOptionPane.ERROR_MESSAGE);
		}
		return cmbXerox;		
	}
}